//
//  MXMineUserInfoController.m
//  HNBaseProject
//
//  Created by xujie on 2024/6/4.
//

#import "MXMineUserInfoController.h"
#import "MxPublicNav.h"
#import "MXUpdateNickNameController.h"
@interface MXMineUserInfoController () <MxNavigationViewDelegate>
@property (nonatomic, strong) MxPublicNav *nav;
@property (nonatomic, strong) UILabel *nicknameLab;
@end

@implementation MXMineUserInfoController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#f5f5f5"];
    [self createUI];
}

- (void)createUI {
    self.nav = [[MxPublicNav alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kNavBarHeight)];
    self.nav.titleLab.text = @"用户资料";
    self.nav.delegate = self;
    [self.view addSubview:self.nav];
    
    MJWeakSelf
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(15, kNavBarHeight+10, kScreenW-30, 100)];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 15;
    [self.view addSubview:bgView];
    bgView.userInteractionEnabled = YES;
    [bgView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [weakSelf editUserName];
    }]];
    
    UIImageView *icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user_nickname"]];
    [bgView addSubview:icon];
    [icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(24);
        make.left.offset(25);
        make.centerY.mas_equalTo(bgView);
    }];
    
    UILabel *titleLab = [[UILabel alloc] init];
    titleLab.text = @"昵称";
    titleLab.textColor = [UIColor dc_colorWithHexString:@"#000000" alpha:0.7];
    titleLab.font = PFRFont(15);
    [bgView addSubview:titleLab];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(icon.mas_right).offset(15);
        make.centerY.mas_equalTo(bgView);
    }];
    
    UIImageView *rightV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mine_right"]];
    [bgView addSubview:rightV];
    [rightV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-15);
        make.centerY.mas_equalTo(bgView);
        make.height.width.mas_equalTo(12);
    }];
    
    MXUserInfoModel *model = [DCCacheTool getCurrentUserInfo];
    self.nicknameLab = [[UILabel alloc] init];
    self.nicknameLab.text = model.name;
    self.nicknameLab.textColor = [UIColor dc_colorWithHexString:@"#000000"];
    self.nicknameLab.font = PFRFont(15);
    [bgView addSubview:self.nicknameLab];
    [self.nicknameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(rightV.mas_left).offset(-20);
        make.centerY.mas_equalTo(bgView);
    }];
    
}

-(void)leftTap {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)editUserName {
    MXUpdateNickNameController *updateVc = [[MXUpdateNickNameController alloc] init];
    [self.navigationController pushViewController:updateVc animated:YES];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self dc_navBarHidden:YES];
}


@end
